﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using nanoCMS.Core.WebUI.Models;
using nanoCMS.Core.WebUI.Models.ViewModels;

namespace nanoCMS.Core.WebUI.Controllers {
	public class UserAdminController : Controller
	{
		private readonly WorldContext worldContext;
		private readonly UserService userService;


		public UserAdminController(WorldContext worldContext)
		{
			this.worldContext = worldContext;
			this.userService = new UserService(worldContext);
		}

		public ActionResult Index()
		{
			
			return PartialView("Index", userService.GetListOfUsers());
		}

		public ActionResult EditUser(int userID)
		{
			UserVM model = userService.GetUser(userID);
			return PartialView("EditUser", model);
		}

		[HttpPost]
		public ActionResult EditUser(UserVM model)
		{
			if (ModelState.IsValid)
			{
//				userService.EditUser(model); TODO
			}
			return RedirectToRoute("UserAdminDefault", new {subaction = "Index"});
			return this.Content("OK");
		}


		public ActionResult ActivateUser(int userID)
		{
			return this.Content(userService.ActivateUser(userID).ToString());
		}
		
	}
}
